/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.type;


import java.util.List;
import dex.compiler.model.base.ParseNode;
import dex.compiler.model.base.Place;


/**
 * An occurrence of a Dex data type.  This is not the superclass of Dex
 * data type <i>definitions</i>; this is the superclass of Dex data 
 * type <i>occurrences</i>.  For instance, consider this code:
 * 
 * <pre>
 * record Foo {
 *     uint32 baz
 * }
 * 
 * Foo globalFoo
 * </pre>
 * 
 * In the above code, the <code>record Foo</code> bit is represented by a 
 * {@link dex.compiler.model.definition.Definition} subclass; the <code>Foo</code>
 * in <code>Foo globalFoo</code> is represented by a <code>Type</code>
 * subclass.
 */
public abstract class TypeNode extends ParseNode {
	
	
	/**
	 * Constructs a new type node.
	 * 
	 * @param place  the place where the type node originated
	 */
	protected TypeNode(Place place) {
		super(place);
	}	

	
	/**
	 * Accepts a visitor.
	 * 
	 * @param visitor  the visitor to accept
	 */
	public abstract void accept(TypeVisitor visitor);


	/**
	 * Returns the list of types as a comma-separated string.
	 * 
	 * @param types  the list of types
	 * @return  the comma-separated string
	 */
	public static String listToString(List<TypeNode> types) {
		StringBuilder result = new StringBuilder();
		if (types.size() > 0) {
			result.append(types.get(0));
			for (int i = 1; i < types.size(); i++) {
				result.append(',').append(types.get(i));
			}
		}
		return result.toString();
	}


}
